package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.common.core.utils.ObjectUtils;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysConditionitemRemoteService;
import com.flyme.module.base.client.entity.SysConditionitem;
import com.flyme.module.base.client.entity.SysExaenum;
import com.flyme.module.base.client.entity.Sysenum;
import com.flyme.module.base.provider.service.SysConditionitemService;
import com.flyme.module.base.provider.service.SysExaenumService;
import com.flyme.module.base.provider.service.SysenumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

/**
 * 证书报考条件项管理
 * @author zyh
 * @date 2020-4-16
 */
@Api(tags = "证书报考条件项")
@RestController
public class SysConditionitemController extends BaseController<SysConditionitemService, SysConditionitem> implements SysConditionitemRemoteService {

    @Autowired
    private SysExaenumService exaenumService;

    /**
     * 企业学习计划列表
     */
    @ApiOperation(value = "证书报考条件项", notes = "证书报考条件项")
    @Override
    public ResultBody list(@ModelAttribute PagerInfo pagerInfo, @ModelAttribute SysConditionitem item) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("*");
        if(!item.getConditionType().equals(0)){
            cq.eq("conditionType", item.getConditionType());
        }
        cq.like("conditionName", item.getConditionName());
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    @Override
    public ResultBody examinationEdit(SysConditionitem conditionitem) {
        if(ObjectUtils.isNotEmpty(conditionitem.getConditionValue())){
            SysExaenum enumItem = exaenumService.findByCode(conditionitem.getConditionValue());
            conditionitem.setSortOrder(enumItem.getSortOrder());
            conditionitem.setWorkValue(Integer.valueOf(enumItem.getScore()));
        }
        Boolean tag = bizService.saveOrUpdate(conditionitem);
        return ResultBody.success("保存成功").setData(tag);
    }

}
